package com.itcast.demoone.kotlin


// Kotlin 默认所有类都是 final 的（不可继承）,  必须使用 open 修饰符使类可继承  ,  方法也必须标记为 open 才能被重写。

open class Animal(var name: String){
   open fun makeSound() {
        println("$name 在发出声音")
    }
}

class Cat(name: String): Animal(name){
    override fun makeSound() {
        super.makeSound()
        println("$name 在喵喵叫")
    }
}

class Dog(name: String): Animal(name) {
    override fun makeSound() {
        super.makeSound()
        println("$name 在汪汪叫")
    }
}


fun main() {
    /*val animal = Animal("某种动物")
    animal.makeSound()*/

    val cat = Cat("小猫")
    cat.makeSound()

    val dog = Dog("小狗")
    dog.makeSound()
}